from pathlib import Path
from vnpy.trader.app import BaseApp
from .ui.main_window import PortfolioTraderWindow
from .engine.portfolio_engine import PortfolioEngine
from vnpy.trader.ui import QtGui

class PortfolioTraderApp(BaseApp):
    """Portfolio Trader Application"""
    
    app_name = "PortfolioTrader"       # 名称
    app_module = "portfolio_trader"     # 模块名
    app_path = "portfolio_trader"       # 路径名
    display_name = "组合交易"           # 显示名称
    engine_class = PortfolioEngine     # 设置引擎类
    widget_name = "PortfolioTraderWindow"  # 窗口类名
    icon_name = str(Path(__file__).parent.joinpath("ui", "portfolio.ico"))
    
    def __init__(self):
        """构造函数"""
        self.engine: PortfolioEngine = None
        self.main_engine = None
        self.event_engine = None
        
    def get_icon(self):
        """获取图标"""
        return QtGui.QIcon(self.icon_name)
        
    def initialize(self, main_engine, event_engine):
        """初始化"""
        self.main_engine = main_engine
        self.event_engine = event_engine
        
    def install(self) -> bool:
        """安装App"""
        return True
        
    def create_widget(self, main_engine=None, event_engine=None):
        """创建窗口"""
        return PortfolioTraderWindow(
            main_engine or self.main_engine,
            event_engine or self.event_engine
        ) 